<html>
	<head>
	<link href="./css/glcss.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="./js/functions.js"></script>
	<script type="text/javascript">
	function check_addar_format (text)
	{
		if (!checkIpv6Format(text))
		{
			document.getElementById("ipv6hint").innerHTML = "The address format not correct.";
		}
		else
		{
			document.getElementById("ipv6hint").innerHTML = "The address format correct.";
		}
	}
	function check_vlink_no (text)
	{
		if (!checkNumber(text))
		{
			document.getElementById("vlinkno").innerHTML = "The input format not correct.";
		}
		else
		{
			//go to server by ajax to check the existence of the vlink number for the VR and user
			document.getElementById("vlinkno").innerHTML = "The input format correct.";
		}
	}
	function check_time_format (this_elem)
	{
		alert(this_elem.value);
		var result = timeFormatCheckAndTransfer(this_elem.value);
		alert(result);
		if (0 == timeFlag)
		{
			this_elem.nextSibling.nextSibling.innerHTML = "The time format not correct.";
		}
		else
		{
			this_elem.nextSibling.nextSibling.innerHTML = "The time format correct.";
		}
	}
	</script>
	</head>


	<body>
		<form name="input" action="<?php echo $_SERVER["PHP_SELF"] . "?addr=" . $_GET["addr"]; ?>" method="post">
			<table>
				<tr>
					<th>Field</th>
					<th>Value</th>
				</tr>
				<tr>
					<td>VR address:</td>
					<td>
						<input type="text" name="loc_ipv6_addr" id="ipv6addr" value="<?php echo $_GET["addr"];?>" onblur="check_addar_format(this.value);" />
						<span id="ipv6hint" class="hint"></span>
					</td>
				</tr>
				<tr>
					<td>Vlink number:</td>
					<td>
						<input type="text" name="vlink_num" onblur="check_vlink_no(this.value);" />
						<span id="vlinkno" class="hint"></span>
					</td>
				</tr>
				<tr>
					<td>Down time:</td>
					<td>
						<input type="text" name="down_time" value="<?php echo date("Y-m-d");?> hh:mm" onblur="check_time_format(this);" />
						<span id="downtime" class="hint"></span>
					</td>
				</tr>
				<tr>
					<td>Up time:</td>
					<td>
						<input type="text" name="up_time" value="<?php echo date("Y-m-d");?> hh:mm" onblur="check_time_format(this);" />
						<span id="uptime" class="hint"></span>
					</td>
				</tr>
				<tr>
					<td>
					<input type="reset" name="" value="Reset" />
					</td>
					<td>
					<input type="submit" name="" value="Submit"/>
					</td>
				</tr>
			</table>
		</form>
<?php
	include_once("../functions.php");
	if (count($_POST))
	{
		$now = strtotime("now");
		$uptime = strtotime($_POST["up_time"]) - $now;
		$downtime = strtotime($_POST["down_time"]) - $now;
		$vlinkctrlxml .= "<vlinkctrl>\n";
		$vlinkctrlxml .= "\t<vr ipv6addr=\"" . $_POST["loc_ipv6_addr"] . "\">\n";
		$vlinkctrlxml .= "\t\t<vlink vlinkno=\"" . $_POST["vlink_num"] . "\">\n";
		$vlinkctrlxml .= "\t\t\t<statectrl>up</statectrl>\n";
		$vlinkctrlxml .= "\t\t\t<time>" . $uptime . "</time>\n";
		$vlinkctrlxml .= "\t\t</vlink>\n";
		$vlinkctrlxml .= "\t\t<vlink vlinkno=\"" . $_POST["vlink_num"] . "\">\n";
		$vlinkctrlxml .= "\t\t\t<statectrl>down</statectrl>\n";
		$vlinkctrlxml .= "\t\t\t<time>" . $downtime . "</time>\n";
		$vlinkctrlxml .= "\t\t</vlink>\n";
		$vlinkctrlxml .= "\t</vr>\n";
		$vlinkctrlxml .= "</vlinkctrl>";
		//echo $xml->vr[0]["ipv6addr"];

		$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
		$connection = socket_connect($socket, 'localhost', 3000);
		
		$msg = ctrl_vlink_by_time_script_parse ($vlinkctrlxml);

		$len = strlen($msg);
		echo $len;
		socket_write($socket,$msg,$len);
	}
?>
	</body>
</html>


